package inventory.controller;

import inventory.common.CommonConstants;
import inventory.common.ResultData;
import inventory.entity.po.EquipmentPo;
import inventory.service.EquipmentService;
import inventory.utils.SelectingCondition;
import inventory.utils.SelectingMapGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author sxt
 * @create 2019-11-10 9:58
 */
@Api(value = "物料相关接口")
@RestController
@RequestMapping(CommonConstants.MATERIAL_PREFIX)
public class MaterialController {

    @Autowired
    private EquipmentService equipmentService;

    @RequestMapping(value = "/getAllEquipments" ,method = RequestMethod.GET)
    public ResultData getAllEquipments(){
        List<EquipmentPo> equipmentPos = equipmentService.queryAllEquipments();
        return new ResultData().OK().setObjs(equipmentPos);
    }

    @RequestMapping(value = "/getEquipmentByCondition" ,method = RequestMethod.POST)
    @ApiImplicitParam(name = "roleId",value = "操作者角色id",required = false)
    public ResultData getEquipmentByCondition(SelectingCondition.MaterialCondition condition){
        SelectingMapGenerator<EquipmentPo> mapGenerator = new SelectingMapGenerator<>(EquipmentPo.class,condition);
        Map resultQueryConditionMap = mapGenerator.getResultQueryConditionMap();
        if(resultQueryConditionMap.isEmpty()){
            return new ResultData().FAILD().setResultIns("未检测到任何有效匹配条件");
        }
        List<EquipmentPo> equipmentPos = equipmentService.queryEquipmentPoByCondition(resultQueryConditionMap);
        return new ResultData().OK().setObjs(equipmentPos);
    }

}
